package single_game.gui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import single_game.logic.race_simulator.Race;

public class ProfileGUI extends JFrame {
	
	private static final long serialVersionUID = 1L;
	private int[] stage;
	public int x = 0,
			   tick = 10,
			   radius = 10;
	private BufferedImage surface;
	private JLabel view;
	
	public ProfileGUI() {
		
		setVisible(true);
		setAlwaysOnTop(true);
		setResizable(false);
		setTitle("Cycling Manager - Stage Profile");
		stage = Race.getInstance().stage;
		setBounds(280, 30, stage.length/tick+6, 325);
		paintProfile();
	}
	
	
	@Override
	public void paint(Graphics g) {
		super.paint(g);
		g.setColor(Color.black);
		g.drawLine(x/tick + 5, 0, x/tick + 5, 325);		
	}
	
	
	private void paintProfile() {
		surface = new BufferedImage(stage.length/tick,300,BufferedImage.TYPE_INT_RGB);
        view = new JLabel(new ImageIcon(surface));
        Graphics g = surface.getGraphics();
        g.setColor(new Color(0, 150, 255));
        g.fillRect(0, 0, stage.length/tick, 300);
        double height = 300;
		for (int i = 0; i < stage.length/tick; i++) {
			height -= nextPoint(stage[i*tick]);
			g.setColor(Color.yellow);
			g.drawLine(i, 300, i, (int)height);
		}	
        g.dispose();
        add(view);
	}
	
	private double nextPoint(int trace) {
		switch (trace) {
			case 3: return 1.4;
			case 4: return 2.0;
			case 7: return -1.0;
			case 8: return -2.0;
			default: return 0.0;
		}
	}

}
